<template>
  <el-dialog :title="title" v-model="dialogVisible" width="500px" append-to-body class="saveVersionDialog "
    :close-on-click-modal="false" :close-on-press-escape="false" @close="dialogClose" @closed="dialogClose">
    <el-form label-position="top" style="padding-top:0;">
      <el-form-item label="描述">
        <el-input v-model="desc" type="textarea" :rows="2" class="show-word-limit" placeholder="请输入描述" maxlength="255"
          show-word-limit />
      </el-form-item>
    </el-form>
    <template #footer>
      <div>
        <el-button @click="dialogClose()">取消</el-button>
        <el-button type="primary" :loading="btnSaveLoading" @click="saveCommit">{{ buttonText }}</el-button>
      </div>
    </template>

  </el-dialog>
</template>

<script setup lang="ts">
import { ref } from "vue"
import { designerStore } from 'src/stores/designerTool/designerTool'
import { ElMessage } from 'element-plus'
import dagGraph from 'src/pages/designerTool/canvas/DagEdit/graph/index.js'
const store = designerStore()
const dialogVisible = ref(false)
const buttonText = ref('保存')
const title = ref('保存新版本')
const btnSaveLoading = ref(false)
const desc = ref('')
function init() {
  dialogVisible.value = true
}
function dialogClose() {
  dialogVisible.value = false
  // this.$emit('update:visible', false)
}
const emits=defineEmits(['successFun'])
function saveCommit() {
  btnSaveLoading.value = true
  dagGraph.saveOrUpdateWorkflowData(true, desc.value).then(res => {
    ElMessage.success('工作流保存版本成功')
    store.SET_PUBLISH_EVENT({
      key: 'updateWorkflowVersionData',
      data: 'init'
    })
    emits('successFun')
    dialogClose()
  }, res => {
    ElMessage.error('工作流保存版本错误:' + res.result)
  }).finally(() => {
    btnSaveLoading.value = false
  })
}
defineExpose({ init })



// export default {
//   name: 'SaveVersionDialog',
//   components: {},
//   data() {
//     return {
//       dialogVisible: false,
//       buttonText: '保存',
//       title: '保存新版本',
//       btnSaveLoading: false,
//       desc: ''
//     }
//   },
//   computed: {
//     ...mapGetters([
//       'workflowInfo'
//     ])
//   },
//   methods: {
//     ...mapMutations({
//       setEventsValue: 'settings/SET_PUBLISH_EVENT'
//     }),

//   }
// }
</script>

<style lang="scss" scoped>
.saveVersionDialog {}
</style>
